<?php


include "./vendor/autoload.php";

\EasySwoole\EasySwoole\Core::getInstance()->initialize();
go(function () {
    $tables = [
//        "role"
    ];

    $tablePre = '';//表前缀
    $path = "App\\Model";//生成地址
    $setIgnoreString = [""];//生成时忽略表名存在的字符,例如user_log将生成=>UserModel
    $mysqlConfig = new \EasySwoole\ORM\Db\Config(\EasySwoole\EasySwoole\Config::getInstance()->getConf('MYSQL'));
    $connection = new \EasySwoole\ORM\Db\Connection($mysqlConfig);

    foreach ($tables as $table){
        //获取连接
        $tableName = $table;
        //获取数据表结构对象
        $tableObjectGeneration = new \EasySwoole\ORM\Utility\TableObjectGeneration($connection, $tableName);
        $schemaInfo = $tableObjectGeneration->generationTable();

        $extendClass = \EasySwoole\ORM\AbstractModel::class;
        $modelConfig = new \EasySwoole\CodeGeneration\ModelGeneration\ModelConfig($schemaInfo, $tablePre, "{$path}", $extendClass);
        $modelConfig->setRootPath(EASYSWOOLE_ROOT);//设置项目运行目录,默认为当前执行脚本目录.
        $modelConfig->setIgnoreString($setIgnoreString);

        $modelGeneration = new \EasySwoole\CodeGeneration\ModelGeneration\ModelGeneration($modelConfig);
        $result = $modelGeneration->generate();//生成成功返回生成文件路径,否则返回false

        $hint = "生成代码：".($result? "成功！地址: {$result}":"失败！");
        print_r($hint);echo PHP_EOL;
    }
});
